package chapters15_bingfa.chapters15_1;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by xinxuchu on 2020/1/24.
 */
public class xiancheng {


    private static int num = 0;

    private static void increamNum(){
        num++;
    }

     static class HelloThread extends Thread{

        private List list;

        public HelloThread(List list) {
            this.list = list;
        }

        @Override
        public void run(){

            increamNum();
            list.add(Thread.currentThread().getName());
            System.out.println("hello1");
            System.out.println("id1 = "+ Thread.currentThread().getId());
            System.out.println("name1 = "+ Thread.currentThread().getName());
        }
    }

    static class HelloThread1 implements Runnable{

        public HelloThread1() {
        }

        @Override
        public void run(){
            System.out.println("hello2");
            System.out.println("id2 = "+ Thread.currentThread().getId());
            System.out.println("name2 = "+ Thread.currentThread().getName());
        }
    }

    public static void main(String[] args) throws InterruptedException {
//        Thread thread = new HelloThread();
//        thread.start();
//
//        Thread thread1 = new Thread(new HelloThread1());
//        thread1.start();

        List list = new ArrayList();


        Thread thread = new HelloThread(list);
        Thread thread2 = new HelloThread(list);
        thread.start();
        thread2.start();
        thread.join();
        thread2.join();

        System.out.println(num);
        System.out.println(list);


    }
}
